package com.atguigu.servlet;

import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.Enumeration;
/*
ServletConfig: 初始化配置参数
        容器会为每一个Servlet对象 创建一个ServletConfig 对象 会在Servlet生命周期方法init() 传入



 */
public class ServletAConfig extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("ServlerAConfig 请求到达了");

        ServletConfig servletConfig = this.getServletConfig();
        //根据名字获取value
        String value = servletConfig.getInitParameter("username");
        System.out.println("value = " + value);
        //获取所有的初始化配置参数的名字
        Enumeration<String> initParameterNames = servletConfig.getInitParameterNames();

        while (initParameterNames.hasMoreElements()){
            //获取每一个名字
            String name = initParameterNames.nextElement();
            //根据名字获取value
            String initParameterValue = servletConfig.getInitParameter(name);

            System.out.println(name+","+initParameterValue);
        }




        resp.getWriter().println("ServlerAConfig Response Success ");


    }
}
